package createThread.cn.tedu.threaddemo.test8;

import java.util.concurrent.BlockingDeque;

/**
 * 饿汉式单例模式
 */
class Test{
    public static  Test instance = new Test();

    public static Test getInstance(){
        return instance;
    }

    private Test() {
    }
}

/**
 * 懒汉式单例模式
 */
class Test1{
    public static  Test1 instance = null;
    public static final Object obj = new Object();
    private Test1() {
    }
    public static Test1 getInstance(){
        synchronized (obj){
            if(instance == null){
                instance = new Test1();
            }
        }
        return instance;
    }
}

public class Demo1 {
    public static void main(String[] args) {
        Test1 i1 = Test1.getInstance();
        Test1 i2 = Test1.getInstance();
        System.out.println(i1 == i2);

    }
}
